package com.atguigu.gmall.publisher.controller;



import com.atguigu.gmall.publisher.bean.TestScorePartBean;
import com.atguigu.gmall.publisher.service.TestScorePartService;
import com.atguigu.gmall.publisher.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController()
public class TestScorePartController {
    @Autowired
    private TestScorePartService testScorePartService;
    @RequestMapping("edu/realtime/score")
    public String getTestPaperStats(@RequestParam(value = "date", defaultValue = "1") Integer date){
        if (date==1){
            date= DateUtil.now();
        }
        List<TestScorePartBean> testScorePartService = this.testScorePartService.getTestScorePartService(date);
        if (testScorePartService == null) {
            return "";
        }

        StringBuilder rows = new StringBuilder();

        for (int i = 0; i < testScorePartService.size(); i++) {
            TestScorePartBean testScorePartBean = testScorePartService.get(i);
            Long good = testScorePartBean.getGood();
            Long pass = testScorePartBean.getPass();
            Long noPass = testScorePartBean.getNoPass();

            rows.append(noPass)
                    .append(",")
                    .append(pass)
                    .append(",")
                    .append(good);

        }




        return  "{\n" +
                "  \"status\": 0,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"categories\": [\n" +
                "      \"不及格\",\n" +
                "      \"及格\",\n" +
                "      \"优秀\"\n" +
                "    ],\n" +
                "    \"series\": [\n" +
                "      {\n" +
                "        \"name\": \"分数段\",\n" +
                "        \"data\": [\n" +
                rows.toString() +
                "        ]\n" +
                "      }\n" +
                "    ]\n" +
                "  }\n" +
                "}";
    }

}
